From e85a40dd36921a17aa7658e162738cb5cad25453 Mon Sep 17 00:00:00 2001 From: "kaf24@firebug.cl.cam.ac.uk" Date: Tue, 18 Oct 2005 19:02:14 +0100 Subject: [PATCH] Remove 'n_vcpu' field from start_info structure. Domain0 simply creates a CPU on every physical CPU. Other domains read the initial VCPU configuration from xenstore. Signed-off-by: Keir Fraser --- .../arch/xen/kernel/smpboot.c | 73 +++++++++++++------ tools/libxc/xc_linux_build.c | 7 +- tools/libxc/xenguest.h | 1 - tools/python/xen/lowlevel/xc/xc.c | 12 ++- tools/python/xen/xend/image.py | 3 +- xen/arch/x86/domain_build.c | 1 - xen/include/public/xen.h | 1 - 7 files changed, 56 insertions(+), 42 deletions(-) diff --git a/linux-2.6-xen-sparse/arch/xen/kernel/smpboot.c b/linux-2.6-xen-sparse/arch/xen/kernel/smpboot.c index a2e6cab984..4b84de07cc 100644 --- a/linux-2.6-xen-sparse/arch/xen/kernel/smpboot.c +++ b/linux-2.6-xen-sparse/arch/xen/kernel/smpboot.c @@ -186,20 +186,20 @@ void vcpu_prepare(int vcpu) void __init smp_prepare_cpus(unsigned int max_cpus) { - int cpu; + int cpu, rc; struct task_struct *idle; - if (max_cpus == 0) { - xen_start_info->n_vcpu = 1; + if (max_cpus == 0) return; - } - - if (max_cpus < xen_start_info->n_vcpu) - xen_start_info->n_vcpu = max_cpus; xen_smp_intr_init(0); - for (cpu = 1; cpu < xen_start_info->n_vcpu; cpu++) { + for (cpu = 1; cpu < max_cpus; cpu++) { + rc = HYPERVISOR_vcpu_op(VCPUOP_is_up, cpu, NULL); + if (rc == -ENOENT) + break; + BUG_ON(rc != 0); + cpu_data[cpu] = boot_cpu_data; cpu_2_logical_apicid[cpu] = cpu; x86_cpu_to_apicid[cpu] = cpu; @@ -220,6 +220,8 @@ void __init smp_prepare_cpus(unsigned int max_cpus) make_page_readonly((void *)cpu_gdt_descr[cpu].address); cpu_set(cpu, cpu_possible_map); + if (xen_start_info->flags & SIF_INITDOMAIN) + cpu_set(cpu, cpu_present_map); vcpu_prepare(cpu); } @@ -243,6 +245,7 @@ void __init smp_prepare_cpus(unsigned int max_cpus) void __devinit smp_prepare_boot_cpu(void) { cpu_possible_map = cpumask_of_cpu(0); + cpu_present_map = cpumask_of_cpu(0); cpu_online_map = cpumask_of_cpu(0); cpu_data[0] = boot_cpu_data; @@ -257,21 +260,14 @@ void __devinit smp_prepare_boot_cpu(void) cpu_set(0, cpu_core_map[0]); } -#ifdef CONFIG_HOTPLUG_CPU - -static void handle_vcpu_hotplug_event( - struct xenbus_watch *watch, const char **vec, unsigned int len) +static void vcpu_hotplug(unsigned int cpu) { - int err, cpu; + int err; char dir[32], state[32]; - char *cpustr; - const char *node = vec[XS_WATCH_PATH]; - if ((cpustr = strstr(node, "cpu/")) == NULL) + if ((cpu >= NR_CPUS) || !cpu_possible(cpu)) return; - sscanf(cpustr, "cpu/%d", &cpu); - sprintf(dir, "cpu/%d", cpu); err = xenbus_scanf(NULL, dir, "availability", "%s", state); if (err != 1) { @@ -279,22 +275,49 @@ static void handle_vcpu_hotplug_event( return; } - if (strcmp(state, "online") == 0) + if (strcmp(state, "online") == 0) { + cpu_set(cpu, cpu_present_map); (void)cpu_up(cpu); - else if (strcmp(state, "offline") == 0) + } else if (strcmp(state, "offline") == 0) { +#ifdef CONFIG_HOTPLUG_CPU (void)cpu_down(cpu); - else - printk(KERN_ERR "XENBUS: unknown state(%s) on node(%s)\n", - state, node); +#else + printk(KERN_INFO "Ignoring CPU%d hotplug request\n", cpu); +#endif + } else { + printk(KERN_ERR "XENBUS: unknown state(%s) on CPU%d\n", + state, cpu); + } +} + +static void handle_vcpu_hotplug_event( + struct xenbus_watch *watch, const char **vec, unsigned int len) +{ + int cpu; + char *cpustr; + const char *node = vec[XS_WATCH_PATH]; + + if ((cpustr = strstr(node, "cpu/")) != NULL) { + sscanf(cpustr, "cpu/%d", &cpu); + vcpu_hotplug(cpu); + } } static int setup_cpu_watcher(struct notifier_block *notifier, unsigned long event, void *data) { + int i; + static struct xenbus_watch cpu_watch = { .node = "cpu", .callback = handle_vcpu_hotplug_event }; (void)register_xenbus_watch(&cpu_watch); + + for_each_cpu(i) + vcpu_hotplug(i); + + printk(KERN_INFO "Brought up %ld CPUs\n", (long)num_online_cpus()); + return NOTIFY_DONE; } @@ -308,6 +331,8 @@ static int __init setup_vcpu_hotplug_event(void) subsys_initcall(setup_vcpu_hotplug_event); +#ifdef CONFIG_HOTPLUG_CPU + int __cpu_disable(void) { cpumask_t map = cpu_online_map; @@ -338,7 +363,7 @@ void __cpu_die(unsigned int cpu) #endif } -#else /* ... !CONFIG_HOTPLUG_CPU */ +#else /* !CONFIG_HOTPLUG_CPU */ int __cpu_disable(void) { diff --git a/tools/libxc/xc_linux_build.c b/tools/libxc/xc_linux_build.c index 1185fc020e..7a3a8737d9 100644 --- a/tools/libxc/xc_linux_build.c +++ b/tools/libxc/xc_linux_build.c @@ -289,7 +289,6 @@ static int setup_guest(int xc_handle, const char *cmdline, unsigned long shared_info_frame, unsigned long flags, - unsigned int vcpus, unsigned int store_evtchn, unsigned long *store_mfn, unsigned int console_evtchn, unsigned long *console_mfn) { @@ -376,7 +375,6 @@ static int setup_guest(int xc_handle, const char *cmdline, unsigned long shared_info_frame, unsigned long flags, - unsigned int vcpus, unsigned int store_evtchn, unsigned long *store_mfn, unsigned int console_evtchn, unsigned long *console_mfn) { @@ -636,7 +634,6 @@ static int setup_guest(int xc_handle, start_info->store_evtchn = store_evtchn; start_info->console_mfn = *console_mfn; start_info->console_evtchn = console_evtchn; - start_info->n_vcpu = vcpus; if ( initrd_len != 0 ) { start_info->mod_start = vinitrd_start; @@ -682,7 +679,6 @@ int xc_linux_build(int xc_handle, const char *ramdisk_name, const char *cmdline, unsigned long flags, - unsigned int vcpus, unsigned int store_evtchn, unsigned long *store_mfn, unsigned int console_evtchn, @@ -756,8 +752,7 @@ int xc_linux_build(int xc_handle, &vstartinfo_start, &vkern_entry, &vstack_start, ctxt, cmdline, op.u.getdomaininfo.shared_info_frame, - flags, vcpus, - store_evtchn, store_mfn, + flags, store_evtchn, store_mfn, console_evtchn, console_mfn) < 0 ) { ERROR("Error constructing guest OS"); diff --git a/tools/libxc/xenguest.h b/tools/libxc/xenguest.h index 1a71ec9d6e..b4003d026a 100644 --- a/tools/libxc/xenguest.h +++ b/tools/libxc/xenguest.h @@ -46,7 +46,6 @@ int xc_linux_build(int xc_handle, const char *ramdisk_name, const char *cmdline, unsigned long flags, - unsigned int vcpus, unsigned int store_evtchn, unsigned long *store_mfn, unsigned int console_evtchn, diff --git a/tools/python/xen/lowlevel/xc/xc.c b/tools/python/xen/lowlevel/xc/xc.c index f28e5ac157..17027cdc2a 100644 --- a/tools/python/xen/lowlevel/xc/xc.c +++ b/tools/python/xen/lowlevel/xc/xc.c @@ -382,7 +382,7 @@ static PyObject *pyxc_linux_build(PyObject *self, uint32_t dom; char *image, *ramdisk = NULL, *cmdline = ""; - int flags = 0, vcpus = 1; + int flags = 0; int store_evtchn, console_evtchn; unsigned long store_mfn = 0; unsigned long console_mfn = 0; @@ -390,19 +390,17 @@ static PyObject *pyxc_linux_build(PyObject *self, static char *kwd_list[] = { "dom", "store_evtchn", "console_evtchn", "image", /* optional */ - "ramdisk", "cmdline", "flags", - "vcpus", NULL }; + "ramdisk", "cmdline", "flags", NULL }; - if ( !PyArg_ParseTupleAndKeywords(args, kwds, "iiis|ssii", kwd_list, + if ( !PyArg_ParseTupleAndKeywords(args, kwds, "iiis|ssi", kwd_list, &dom, &store_evtchn, &console_evtchn, &image, /* optional */ - &ramdisk, &cmdline, &flags, - &vcpus) ) + &ramdisk, &cmdline, &flags) ) return NULL; if ( xc_linux_build(xc->xc_handle, dom, image, - ramdisk, cmdline, flags, vcpus, + ramdisk, cmdline, flags, store_evtchn, &store_mfn, console_evtchn, &console_mfn) != 0 ) return PyErr_SetFromErrno(xc_error); diff --git a/tools/python/xen/xend/image.py b/tools/python/xen/xend/image.py index 23cc89cfbc..5453b1089a 100644 --- a/tools/python/xen/xend/image.py +++ b/tools/python/xen/xend/image.py @@ -185,8 +185,7 @@ class LinuxImageHandler(ImageHandler): store_evtchn = store_evtchn, console_evtchn = console_evtchn, cmdline = self.cmdline, - ramdisk = self.ramdisk, - vcpus = self.vm.getVCpuCount()) + ramdisk = self.ramdisk) if isinstance(ret, dict): self.set_vminfo(ret) return 0 diff --git a/xen/arch/x86/domain_build.c b/xen/arch/x86/domain_build.c index 38a3cb2c99..c702872206 100644 --- a/xen/arch/x86/domain_build.c +++ b/xen/arch/x86/domain_build.c @@ -588,7 +588,6 @@ int construct_dom0(struct domain *d, si = (start_info_t *)vstartinfo_start; memset(si, 0, PAGE_SIZE); si->nr_pages = nr_pages; - si->n_vcpu = num_online_cpus(); if ( opt_dom0_translate ) { diff --git a/xen/include/public/xen.h b/xen/include/public/xen.h index c88113ab6c..d21a41205d 100644 --- a/xen/include/public/xen.h +++ b/xen/include/public/xen.h @@ -423,7 +423,6 @@ typedef struct start_info { unsigned long mfn_list; /* VIRTUAL address of page-frame list. */ unsigned long mod_start; /* VIRTUAL address of pre-loaded module. */ unsigned long mod_len; /* Size (bytes) of pre-loaded module. */ - uint32_t n_vcpu; int8_t cmd_line[MAX_GUEST_CMDLINE]; } start_info_t; -- 2.30.2